package br.cns;

import static br.cns.MetricHelper.getInstance;
import static br.cns.TMetric.ALGEBRAIC_CONNECTIVITY;
import static br.cns.TMetric.AVERAGE_DEGREE;
import static br.cns.TMetric.AVERAGE_PATH_LENGTH;
import static br.cns.TMetric.DENSITY;
import static br.cns.TMetric.DIAMETER;
import static br.cns.TMetric.NATURAL_CONNECTIVITY;
import static org.junit.Assert.assertEquals;

import java.util.Vector;

import org.junit.Test;

import br.cns.experiments.ComplexNetwork;
import br.cns.models.TModel;

public class FinlandiaTest {
	private static final Integer[][] net = new Integer[][]{
			{0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
			{1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0},
			{1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0},
			{0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0},
			{0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0},
			{0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0},
			{0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0},
			{0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1},
			{0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1},
			{0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1},
			{0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1},
			{0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0}};
	
	@Test
	public void testAlgebraicConnectivity() {
		double value = getInstance().calculate(ALGEBRAIC_CONNECTIVITY, net);
		System.out.printf("Algebraic Connectivity = %.4f\n", value);
		assertEquals(value, 0.8814, 4);
	}
	
	@Test
	public void testAverageDegree() {
		double value = getInstance().calculate(AVERAGE_DEGREE, net);
		System.out.printf("Average Degree = %.4f\n", value);
		assertEquals(value, 3.1667, 4);
	}
	
	@Test
	public void testAveragePathLength() {
		double value = getInstance().calculate(AVERAGE_PATH_LENGTH, net);
		System.out.printf("Average Pathlength = %.4f\n", value);
		assertEquals(value, 2.0909, 4);
	}
	
	@Test
	public void testDensity() {
		double value = getInstance().calculate(DENSITY, net);
		System.out.printf("Density = %.4f\n", value);
		assertEquals(value, 0.2879, 4);
	}
	
	@Test
	public void testDiameter() {
		double value = getInstance().calculate(DIAMETER, net);
		System.out.printf("Diameter = %.4f\n", value);
		assertEquals(value, 4.0000, 4);
	}
	
	@Test
	public void testNaturalConnectivity() {
		double value = getInstance().calculate(NATURAL_CONNECTIVITY, net);
		System.out.printf("Natural Connectivity = %.4f\n", value);
		assertEquals(value, 1.4656, 4);
	}

	@Test
	public void testHvc() {
		ComplexNetwork cn = new ComplexNetwork(0, net, new double[net.length][net.length], TModel.CUSTOM, new Vector<TMetric>());
		cn.calculateRealEigenvalues();
		double value = cn.getMaxOddComponent();
		System.out.printf("HVC = %.4f\n", value);
		assertEquals(value, 1.0, 4);
	}

	@Test
	public void testFzc() {
		ComplexNetwork cn = new ComplexNetwork(0, net, new double[net.length][net.length], TModel.CUSTOM, new Vector<TMetric>());
		cn.calculateRealEigenvalues();
		double value = cn.getFirstZeroEvenComponent();
		System.out.printf("FZC = %.4f\n", value);
		assertEquals(value, 1.0, 4);
	}
}
